home *** CD-ROM | disk | FTP | other *** search
/ C++ für Kids / C++ for kids.iso / Buch / Rund2.cpp < prev    next >
C/C++ Source or Header  |  1998-12-29  |  2KB  |  75 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl\vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "Rund2.h"
  6. //---------------------------------------------------------------------------
  7. #pragma resource "*.dfm"
  8.  
  9. class TKreis
  10. {
  11. public:
  12.   int x, y, Dicke;
  13.   void Erscheinen (void);
  14.   void Bewegen (void);
  15.   void Verschwinden (void);
  16.   TKreis (int xx, int yy, int dd);
  17. };
  18.  
  19. TKreis *Kreis;
  20. TForm1 *Form1;
  21. //---------------------------------------------------------------------------
  22. TKreis::TKreis(int xx, int yy, int dd)
  23. {
  24.   x = xx; y = yy; Dicke = dd;
  25. }
  26. //---------------------------------------------------------------------------
  27. void TKreis::Erscheinen (void)
  28. {
  29.   Form1->Canvas->Ellipse (x, y, x+Dicke, y+Dicke);
  30. }
  31. //---------------------------------------------------------------------------
  32. void TKreis::Bewegen (void)
  33. {
  34.   TRect Quelle, Ziel;
  35.   for (int i=x-5; i<Form1->ClientWidth-Dicke-x-5; i++)
  36.   {
  37.     Quelle = Rect(i,   y-5, i+Dicke+5, y+Dicke+5);
  38.     Ziel   = Rect(i+1, y-5, i+Dicke+6, y+Dicke+5);
  39.     Form1->Canvas->CopyRect(Ziel, Form1->Canvas, Quelle);
  40.     // Bremse, abhΣngig vom Prozessortakt!
  41.     for (int j=0; j<1000000; j++) ;
  42.   }
  43. }
  44. //---------------------------------------------------------------------------
  45. void TKreis::Verschwinden (void)
  46. {
  47.   Form1->Refresh ();
  48. }
  49. //---------------------------------------------------------------------------
  50. __fastcall TForm1::TForm1(TComponent* Owner)
  51.     : TForm(Owner)
  52. {
  53. }
  54. //---------------------------------------------------------------------------
  55. void __fastcall TForm1::Button1Click(TObject *Sender)
  56. {
  57.   Kreis->Erscheinen ();
  58. }
  59. //---------------------------------------------------------------------------
  60. void __fastcall TForm1::Button2Click(TObject *Sender)
  61. {
  62.   Kreis->Bewegen ();
  63. }
  64. //---------------------------------------------------------------------------
  65. void __fastcall TForm1::Button3Click(TObject *Sender)
  66. {
  67.   Kreis->Verschwinden ();
  68. }
  69. //---------------------------------------------------------------------------
  70. void __fastcall TForm1::FormCreate(TObject *Sender)
  71. {
  72.   Kreis = new TKreis (30, 30, 150);
  73. }
  74. //---------------------------------------------------------------------------
  75.